import {createRouter, createWebHistory} from "vue-router";
import Base from "../views/base.vue";
import Request from "../utils/request";
import axios from "axios";
import config from "../utils/config";
import Methods from "../utils/Methods";

const routes = [
    {
        path: '/',
        redirect: '/home'
    }, {
        path: "/",
        name: "base",
        component: Base,
        children: [
            {
                path: "/home",
                name: "home",
                meta: {
                    title: '多拉贡网络科技'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/home.vue")
            }, {
                path: "/game",
                name: "game",
                meta: {
                    title: '老头环地图'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/game.vue")

            },{
                path: "/code",
                name: "codelist",
                meta: {
                    title: '程序博客'
                },
                component: () => import ( /* webpackChunkName: "Slide" */ "../views/code.vue")
            },{
                path: "/tools",
                name: "tools",
                meta: {
                    title: '工具'
                },
                component: () => import ( /* webpackChunkName: "Slide" */ "../views/tools.vue")
            },{
                path: "/codedetail",
                name: "codedetail",
                meta: {
                    title: ''
                },
                component: () => import ( /* webpackChunkName: "Slide" */ "../views/codedetail.vue")
            }
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import ( /* webpackChunkName: "login" */ "../views/login.vue")
    }, {
		path: "/404",
		name: "404",
		meta: {
			title: '页面不存在'
		},
		component: () => import ( /* webpackChunkName: "login" */ "../views/404.vue")
	}, {
		path: "/version",
		name: "version",
		meta: {
			title: '接口版本'
		},
		component: () => import ( /* webpackChunkName: "login" */ "../views/version.vue")
	},{
        path: "/test",
        name: "test",
        meta: {
            title: 'JJ chat'
        },
        component: () => import ( /* webpackChunkName: "login" */ "../views/test.vue")
    }

];
const router = createRouter({
    history: createWebHistory('/'),
    routes
})

const needToken = []

router.beforeEach((to, from, next) => {
    document.title = to.meta.title;
    // let token = Methods.getLocalStorage('token')
    if(to.matched.length === 0) {
        next({path:'/404'})
    }else {
        next()
    }

});

export default router;
